<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
            display: flex;
            width: 1200px;
            margin: auto;
        }

        .content {
            height: 300px;
            flex: 1;
            border: 1px solid #000;
        }
    </style>
</head>

<body>

    <div class="box">
        <ul>
            <li>
                <a href="#first">first</a>
            </li>
            <li>
                <a href="#second">second</a>
            </li>
            <li>
                <a href="#third">third</a>
            </li>
        </ul>
        <div class="content">
            <!-- 显示对应的内容 -->

            <!-- <div>first</div> -->

        </div>
    </div>

    <script>

        // 把内容定义在字符串中

        const t1 = '<div>first</div>' ;

        const t2 = '<div>second</div>' ;

        const t3 = '<div>third</div>' ;


        const oContent = document.querySelector('.content') ;


        // 默认页面打开的时候显示第一个模块   --- 相当于主动触发事件 ---- 调用这个事件处理函数
        hashHandle() ;

        // hash
        //    当锚点值发生改变时触发这个事件  onhashchange
        window.onhashchange = hashHandle


        // handle 处理
        function hashHandle() {
            // console.log(1)
            const {hash} = location ;
            if(!hash) {
                oContent.innerHTML = t1
            }

            switch(hash) {
                case '#first' : oContent.innerHTML = t1 ; break ;
                case '#second' : oContent.innerHTML = t2 ; break ;
                case '#third' : oContent.innerHTML = t3 ; break ;
            }
        }

    </script>

</body>

</html>